#include "CFpsController.h"
namespace Framework
{

	void CFpsController::SetLimitFPS(float limitFPS)
	{
		m_iLimitFPS=limitFPS;
		m_iLimmitFrameDt=1000/limitFPS;
	}
	void CFpsController::BeginCounter()
	{
		if (m_IsPerfHardware)
		{
			QueryPerformanceCounter(&m_StartCount);
		} 
		else
		{
			m_StartTime=timeGetTime();
		}
	}

	void CFpsController::EndCounter()
	{
		if (m_IsPerfHardware)
		{
			LARGE_INTEGER m_EndCount;
			QueryPerformanceCounter(&m_EndCount);
			delta_Time=(m_EndCount.QuadPart-m_StartCount.QuadPart)/(float)m_Frequency.QuadPart;
		} 
		else
		{
			DWORD m_EndTime=timeGetTime();
			delta_Time=(float)(m_EndTime-m_StartTime)/1000;
		}
		if (delta_Time<m_iLimmitFrameDt)
		{
			m_iFrameDt=m_iLimmitFrameDt;
			Sleep(m_iLimmitFrameDt-delta_Time);
		} 
		else
		{
			m_iFrameDt=delta_Time;
			Sleep(1);
		}
	}
}

